<?php
namespace app\common\validate;
use think\facade\Db;
use think\Validate;

class House extends Validate
{

    protected $rule=[
        'id'    =>'require',
        'address'    =>'require',
        'area'    =>'require',
        'house_type'    =>'require',
        'price'    =>'require|number',
        'time_num'    =>'require',
        'cate'    =>'require',

    ];
    protected $message = [
        'id.require'    => '关键参数不能为空',

        'address.require'    => '房屋地址不能为空',
        'area.require'    => '房屋面积不能为空',
        'house_type.require'    => '户型不能为空',
        'price.require'    => '房租金额不能为空',
        'time_num.require'    => '收取频次不能为空',
        'cate.require'    => '房产类型数不能为空',
    ];
    protected $scene = [
        'add' =>['address','area','house_type','price','time_num','cate'],
        'edit' =>['id','address','area','house_type','price','time_num','cate'],
    ];

    protected function checkmobile($value,$rule,$data){
        if(!is_numeric($value)){
            return '请输入数字';
        }
        if(strlen($value) != 11){
            return '请输入11位手机号';
        }
        if (!preg_match("/^1[3456789]\d{9}$/", $value)) {
            return '手机号码格式不正确';
        }
        return true;
    }
    protected function checkuniquemobile($value,$rule,$data){
        $one = DB::name('users')->where('mobile','=',$value)->find();
        if($one){
            return '手机号已经存在';
        }
        return true;
    }



}